//
//  PSEthernetPacket.m
//  PacketSniffer
//
//  Created by nark on 01/05/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "PSEthernetPacket.h"
#import "header.h"

@implementation PSEthernetPacket

@synthesize destinationMACAddress;
@synthesize sourceMACAddress;
@synthesize type;

- (id) init
{
	self = [super init];
	if (self != nil) {

	}
	return self;
}



- (NSString *)description
{
	return [NSString stringWithFormat:@"Ethernet Packet - %@ -> %@", sourceMACAddress, destinationMACAddress];
}


- (NSMutableDictionary *)properties {
	
	NSMutableDictionary *propertyDict = [[NSMutableDictionary alloc] init];
	
	[propertyDict setValue:self.sourceMACAddress								
					forKey:@"Source MAC Address"];
	
	[propertyDict setValue:self.destinationMACAddress							
					forKey:@"Destination MAC Address"];
	
	[propertyDict setValue:self.dateReceived			
					forKey:@"Date Received"];
	
	[propertyDict setValue:[self explicitType]	
					forKey:@"Type"];
	
	[propertyDict setValue:[NSString stringWithFormat:@"%d", self.length]		
					forKey:@"Total Length"];
	
	[propertyDict setValue:[NSString stringWithFormat:@"%d", self.capturedLength]	
					forKey:@"Captured Length"];
	
	return propertyDict;
}


- (NSString *)explicitType {
	NSString *result = @"Unsupported Type";
	
	switch (self.type) {
		case ETHERTYPE_IP:
			result = @"IP";
			break;
		case ETHERTYPE_IPV6:
			result = @"IPv6";
			break;
		case ETHERTYPE_ARP:
			result = @"ARP";
			break;
		case ETHERTYPE_REVARP:
			result = @"REARP";
			break;
	}
	
	return result;
}


@end
